package com.scriptback.entity;


import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

/**
 * 脚本实体类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "Scripts")
@Entity
public class Scripts {

    @Id
    private String id; // 脚本ID

    @Column(name = "project_id",nullable = false)
    private String projectId; // 所属项目ID

    @Column(name ="name",nullable = false,length = 100)
    private String name; // 脚本名称

    @Column(name = "description",columnDefinition = "TEXT")
    private String description; // 脚本描述

    @Column(name = "code", nullable = false, columnDefinition = "LONGTEXT")
    private String code; // 脚本代码

    public Scripts(String projectId, String name, String code,String description) {
        this.projectId = projectId;
        this.name = name;
        this.code = code;
        this.description = description;
    }

    @PrePersist
    public void generateId() {
        if (this.id == null) {
            this.id = UUID.randomUUID().toString();
        }
    }

}
